<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:head>

        <title>#{msg.titoloGestioneFornitura}</title>
        <link href="../Style/oneColFixCtrHdr.css" type="text/css" rel="stylesheet"/>

    </h:head>

    <h:body>

        #{redirect.redirectAddettoNegozio(gestioneNegozio, "/E-Market-war/Login.jsf")}
        #{gestioneNegozio.setFornitura(gestioneFornitura)}
        #{gestioneNegozio.setRiassortimento(gestioneRiassortimento)}
        <div class="container">

            <ui:include src="../Header.xhtml"/>

            <div class="content">

                <h:form>

                    <p:breadCrumb>  

                        <p:menuitem value="Home" url="GestioneNegozio.jsf"/>
                        <p:menuitem value="#{msg.addRiassortimento}" url="GestioneRiassortimento.jsf"/> 
                        <p:menuitem value="#{msg.cronologiaLink}" url="RiepilogoProdotti.jsf"/> 
                        <p:menuitem value="#{msg.spezioneOrdineGestione}" url="GestioneOrdini.jsf"/>  
                    </p:breadCrumb>
                </h:form>

                <h:form id="messagesForm">

                    <p:messages showDetail="false" autoUpdate="true" closable="true" />
                </h:form>

                <h:form id="fornituraSel" enctype="multipart/form-data" style="margin-top: 20px">

                    #{gestioneFornitura.dimenticaSelezione()}

                    <table>

                        <tr>

                            <td>

                                <h4>

                                    <p:outputLabel value="#{msg.selMarchio}"/>
                                </h4>

                                <p:selectOneListbox  style="width:250px;height:400px" required="true" converter="marchioConverter" requiredMessage="#{msg.marchioRequestM}" var="mar" value="#{gestioneFornitura.marchio}">

                                    <f:selectItems value="#{gestioneFornitura.marchi}" var="m" itemLabel="#{m.nome}" itemValue="#{m}"/>

                                    <p:column>  

                                        <p:graphicImage value="#{mar.foto.fotoPath()}" width="50" />  
                                    </p:column>  

                                    <p:column>  

                                        #{mar.nome}  
                                    </p:column>
                                    <p:ajax event="valueChange" update="valProdotti" listener="#{gestioneFornitura.ottieniProdotti()}"/>
                                </p:selectOneListbox>
                            </td>

                            <td>

                                <h4>

                                    <p:outputLabel value="#{msg.selProdotto}"/>
                                </h4>

                                <p:selectOneListbox id="valProdotti" style="width:250px;height:400px" required="true" converter="prodottoConverter" requiredMessage="#{msg.prodottoRequestM}" var="prod" value="#{gestioneFornitura.prodotto}">

                                    <f:selectItems value="#{gestioneFornitura.prodotti}" var="p" itemLabel="#{p.nome}" itemValue="#{p}"/>

                                    <p:column>  

                                        <p:graphicImage value="#{prod.foto.fotoPath()}" width="50" />  
                                    </p:column>

                                    <p:column>  

                                        #{prod.nome}  
                                    </p:column>
                                    <p:ajax  update="descProdotto"/>
                                </p:selectOneListbox>

                            </td>

                            <td>


                                <p:panel id="descProdotto" header="#{msg.fornituraForm}" style="width:425px;height:350px">

                                    <h:panelGrid  columns="2">

                                        <h:graphicImage value="#{gestioneFornitura.prodotto.foto.fotoPath()}" width="50"/>
                                        <p:outputLabel value="#{gestioneFornitura.prodotto.nome}"/>
                                    </h:panelGrid>
                                    <h:outputLabel value="#{gestioneFornitura.prodotto.descrizione}"/>
                                    <hr/>

                                    <h:panelGrid id="quantita" columns="2" style="margin-bottom:10px; margin-top: 20px">  

                                        <p:outputLabel for="prezzoFornitura" value="#{msg.prezzoForm}"/>

                                        <p:spinner id="prezzoFornitura"   required="true" value="#{gestioneFornitura.prezzo}" converterMessage="#{msg.prezzoErrorM}"  stepFactor="0.5" requiredMessage="#{msg.quantitaRequestM}"/> 

                                        <p:outputLabel for="quantitaFornitura" value="#{msg.quantitaForm}"/>

                                        <p:spinner id="quantitaFornitura" required="true" requiredMessage="#{msg.quantitaRequestM}" converterMessage="#{msg.quantitaErrorM}" value="#{gestioneFornitura.quantita}" stepFactor="1"/>
                                    </h:panelGrid>
                                    <p:commandButton value="#{msg.addProdotto}" update=":messagesForm, :riepilogoFornitura,:fornituraSel" actionListener="#{gestioneFornitura.creaFornitura()}"/>
                                </p:panel>
                            </td>
                        </tr>
                    </table>
                </h:form>
                <br/>
                <hr/>

                <h3>

                    <p:outputLabel value="#{msg.fornituraRiepilogo}"/>
                </h3>

                <p:dataTable id="riepilogoFornitura" value="#{gestioneFornitura.fornitureEstese}" var="p" paginator="true" rows="10" 
                             rowsPerPageTemplate="5,10,15" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             emptyMessage="#{msg.noForniture}">

                    <p:column>

                        <f:facet name="header">  

                            <h:outputText value="#{msg.codBarreTable}" />  
                        </f:facet> 
                        <h:outputLabel value="#{p.fornitura.prodotto.codiceBarre}"/>
                    </p:column>

                    <p:column>

                        <f:facet name="header">  

                            <h:outputText value="#{msg.prodottoTable}" />  
                        </f:facet>
                        <h:outputLabel value="#{p.fornitura.prodotto.nome}"/>
                    </p:column>

                    <p:column>  

                        <f:facet name="header">  

                            <h:outputText value="#{msg.quantitaTable}" />  
                        </f:facet>  
                        <h:outputLabel value="#{p.fornitura.quantita}"/>
                    </p:column>

                    <p:column>

                        <f:facet name="header">  

                            <h:outputText value="#{msg.prezzoTable}" />  
                        </f:facet> 
                        <h:outputLabel value="#{p.dettaglioPrezzo.prezzo}"/>
                    </p:column>
                </p:dataTable>

                <h:form>

                    <h:panelGrid columns="4">

                        <p:commandButton value="#{msg.rimuoviRecente}" update=":messagesForm, :riepilogoFornitura, :fornituraSel"  actionListener="#{gestioneFornitura.rimuoviFornituraRecente()}"/>
                        <p:commandButton value="#{msg.rimuoviTutto}" update=":messagesForm, :riepilogoFornitura, :fornituraSel"  actionListener="#{gestioneFornitura.svuotaRiepilogo()}"/>
                        <p:commandButton value="#{msg.confermaDati}" update=":messagesForm, :riepilogoFornitura, :fornituraSel" actionListener="#{gestioneFornitura.confermaFornitura()}"/>
                    </h:panelGrid>
                </h:form>
            </div>
            <ui:include src="../Footer.xhtml"/>
        </div> 
    </h:body>
</html>